package com.ifreshwing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ifreshwing.bean.HomeRegionListBean;
import com.ifreshwing.userpark.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lz on 2017/4/28.
 * 首页-listview
 */

public class HomeListAdapter extends BaseAdapter {

    private Context context;
    private List<HomeRegionListBean> list;

    public HomeListAdapter(Context context, List<HomeRegionListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return Long.parseLong(list.get(position).getParkingRegion_id());
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_home_parking, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else vh = (ViewHolder) convertView.getTag();

        vh.img.setImageResource(R.mipmap.right);
        vh.tvRegion.setText(list.get(position).getParkingRegion_name());
        vh.rlItem.setTag(list.get(position).getParkingRegion_id());
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.tv_region)
        TextView tvRegion;
        @BindView(R.id.img)
        ImageView img;
        @BindView(R.id.rl_item)
        RelativeLayout rlItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
